package com.usc.csci588.chaltrojan.login;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.util.Log;
import android.widget.DatePicker;
import android.widget.TextView;


public class DatePickerFragment extends DialogFragment implements
		DatePickerDialog.OnDateSetListener {

	public TextView tv;
	public String date;
//	int mm;
//	int dd;
//	int yy;
	

	public DatePickerFragment() {
	    tv = null;
	}	

	public DatePickerFragment(TextView edit_text, String dt) {
	    tv = edit_text;
	    date = dt;
	}	
	
	public DatePickerFragment(TextView edit_text) {
	    tv = edit_text;
	    this.date = "";
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current date as the default date in the picker
		
		final Calendar c = Calendar.getInstance();
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);

		// Create a new instance of DatePickerDialog and return it
		return new DatePickerDialog(getActivity(), this, year, month, day);
	}
	
	

	@Override
	public void onDateSet(DatePicker dp, int year, int month, int day) {		
		// Do something with the date chosen by the user
//		TextView trip_date = (TextView) ( getView().findViewById(R.id.trip_date) );
		
//		Date date = new Date(year, month, day);
		
//		mm = month;
//		yy=year;
//		dd = day;
		
		Date date1=new Date  (year-1900, month, day);
		
				
		SimpleDateFormat sdf1 = new SimpleDateFormat("EEE, MMM dd, ''yy");
		String ds1 = sdf1.format(date1);
		
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
		String ds2 = sdf2.format(date1);		
		
		
//		tv.setText(month+"-"+day+"-"+year);		
//		tv.setText(year+"-"+month+"-"+day);		
		tv.setText(ds2);		
		
		date = ds1;
		Log.d("ui", "DPF 1 : date --> "+this.date);
	}
	
//	public int getMonth(){
//		return mm;
//	}
//	
//	public int getDay(){
//		return dd;
//	}
//
//	public int getYear(){
//		return yy;
//	}

	public String getDate(){
		Log.d("ui", "DPF 2 : date --> "+this.date);
		return this.date;
	}
	
	
}